
<?php 
include('../../Connections/KRAPPERCON.php');
$oper = '';
if (isset($_POST['oper'])){
$oper = $_POST['oper'];
}
if (isset($_GET['oper'])){
$oper = $_GET['oper'];
}

if ($oper == 'em'){
	$fecmig = $_POST['t_fecmig'];
	$refmig = $_POST['t_refmig'];
	$txtmig = $_POST['t_txtmig'];
	$items = $_POST['items'];
	// 190000003|1|posicion1|1|2001#190000003|2|posicion2|1|2001#
	$sql = "call sp_saveMIGO('".$fecmig."','".$refmig."','".$txtmig."','".$items."', '".$user_now."');";
	doEcho ($sql);

	$res = $mysqli->query($sql) or die($mysqli->error.__LINE__);;
//	$res = $mysqli->query($sql);
	if ($res){
	?>
	<script type="text/javascript">
	<?php 
		if ($row = $res->fetch_assoc()){
		$newnro = $row['newnro'];
			if ($newnro > 0){
			// Se grabo OK el Documento
			?>
			showOk('Se grabo el Documento Nro. <?php echo $newnro; ?> satisfactoriamente.');
			$('#sp_nomig').html('<?php echo $newnro; ?>');
			$('#tbl_dat_mig input,#tbl_dat_mig select').disable();
			<?php
			}
			else {
			?>
			showOk('Error al registrar la EM : \n<?php echo $row['msg_err'].'-Doc.Compra : '.$row['docpos']; ?>');		
			<?php
			}
		}
	?>
	</script>
	<?php 
	$res->close();
		if ($mysqli->more_results())
		$mysqli->check_result();
	}
}
elseif ($oper == 'aem'){	
	// 190000003|1|posicion1|1|2001#190000003|2|posicion2|1|2001#
	$docm = $_POST['documento'];
	$sql = "call sp_anularMIGO('".$user_now."','".$docm."');";
	doEcho ($sql);

	$res = $mysqli->query($sql) or die($mysqli->error.__LINE__);
//	$res = $mysqli->query($sql);
	if ($res){
	?>
	<script type="text/javascript">
	<?php 
		if ($row = $res->fetch_assoc()){
		$newnro = $row['newnro'];
			if ($newnro > 0){
			// Se grabo OK el Documento
			?>
			showOk('Documento Anulado correctamente con <?php echo $newnro; ?> .');
			$('#sp_nomig').html('<?php echo $newnro; ?>');
			$('#tbl_dat_mig input,#tbl_dat_mig select').disable();
			<?php
			}
			else {
			?>
			showOk('Error al anular Documento : \n<?php echo $row['msg_err'].'\nDoc.Compra : '.$row['docpos']; ?>');		
			<?php
			}
		}
	?>
	</script>
	<?php 
	$res->close();
		$mysqli->check_result();
	}
}
?>